<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<%@include file="/web/page/head.jsp" %>
<title>Insert title here</title>
</head>
<body>
<form class="layui-form" method="post">
			<div class="layui-form-item">
			<label class="layui-form-label">编号:</label>
			<div class="layui-input-inline">
				<input type="text" name="code" class="layui-input" lay-verity="required" placeholder="必填" />
			</div>
			</div>
			
			<div class="layui-form-item">
			<label class="layui-form-label">名称:</label>
			<div class="layui-input-inline">
				<input type="text" name="name" class="layui-input" lay-verity="required" placeholder="必填" />
			</div>
			</div>
			
			
			<div class="layui-form-item">
			<label class="layui-form-label"></label>
			<div class="layui-input-inline">
				<input type="button" class="layui-btn" lay-submit lay-filter="add" value="确定" />
				<input type="button" class="layui-btn" onclick="closeThis()" value="取消" />
			</div>
			</div>
			<input type="hidden" name="action" value="add" />
</form>

<script type="text/javascript">
var layer = layui.layer;
var $ = layui.jquery;
var laytpl = layui.laytpl;
var element = layui.element;
var form = layui.form
function closeThis(){
	var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
	parent.layer.close(index); //再执行关闭   
}
form.on("submit(add)",function(data){
	console.log(data)
	$.ajax({
		url:"<%=app %>/EmployeeServlet",
		data:data.field,
		dataType:'text',
		type:'post',
		success:function(data){
			console.log(data)
			if(data==1){
				layer.msg('添加成功',closeThis);
			}else if(data=="rgp"){
				layer.msg('账号重复');
			}else{
				layer.msg('添加失败');
			}
		}
	})
})
</script>
</body>
</html>